﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
   
    <script src="~/scripts/jquery-3.5.1.js"></script>

    <link href="~/lib/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/layui-v2.5.6/layui/layui.js"></script>
  
</head>
<body>
    <div>
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">推荐位置</label>
                <div class="layui-input-inline">
                    <input type="text" name="spuName" id="SpuName" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button class="layui-btn" id="btnSearch">查询</button>
                    <button type="reset" class="layui-btn layui-btn-primary" id="btnAdd">添加</button>
                </div>
            </div>
        </form>
        <table id="demo" lay-filter="test"></table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script>
            layui.use(['table', 'laydate', 'layer', 'form'], function () {
                var table = layui.table;
                var laydate = layui.laydate;
                var layer = layui.layer;
                var form = layui.form;
                var $ = layui.$;
                //第一个实例
                table.render({
                    elem: '#demo'
                  , height: 312,
                    id: "ser"
                  , url: '/Shop/GetShopType/' //数据接口
                  , page: true //开启分页
                  , cols: [[ //表头
                    { field: 'id', title: 'ID', width: 120, sort: true, fixed: 'left' }
                    , { field: 'supClassName', title: '商品类型', width: 120, sort: true }
                    , { field: 'tier', title: '类型层级', width: 120, sort: true }
                      , { fixed: 'right', width: 250, align: 'center', toolbar: '#barDemo' }
                  ]]
                });
                $("#btnSearch").click(function () {
                    table.reload('ser', {
                        where: {
                            spuName: $("#SpuName").val(),
                        } //设定异步数据接口的额外参数
                        //,height: 300
                    });
                    return false;
                })
                $("#btnAdd").click(function () {
                    layer.open({
                        type: 2,
                        area: ['500px', '500px'],
                        content: '/Shop/ProductTypeAdd' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                    return false;
                })
                table.on('tool(test)', function (obj) {
                    var data = obj.data;
                    var layEvent = obj.event;
                    var tr = obj.tr;

                    if (layEvent === 'del') {
                        layer.confirm('真的删除行么', function (index) {
                            $.post("/ProductType/DelProductType", { id: data.id }, function (re) {
                                if (re > 0) {
                                    layer.msg("删除成功");
                                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                } else {
                                    layer.msg("删除失败");
                                }
                            }, "text");
                        });
                    } else if (layEvent === 'edit') {
                        layer.open({
                            type: 2,
                            area: ['500px', '500px'],
                            content: '/ProductType/TypeEditView/' + data.id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        });
                        return false;
                    }
                });
            });
        </script>
    </div>
</body>
</html>
